package pers.kw.controller;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pers.kw.entity.OauthClientDetailsDO;
import pers.kw.service.OauthClientDetailsService;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@RestController
public class ClientMgrController {

    private static final Logger logger = LoggerFactory.getLogger(ClientMgrController.class);

    @Resource
    private OauthClientDetailsService oauthClientDetailsService;

    @RequestMapping(value = "/client/mgr/list")
    public List<OauthClientDetailsDO> list() {
        logger.info("查询客户端信息列表");
        return oauthClientDetailsService.list();
    }

    @RequestMapping(value = "/client/mgr/add")
    public Integer add(@Valid @RequestBody OauthClientDetailsDO clientDetailsDO) {
        logger.info("添加应用请求：{}", JSON.toJSONString(clientDetailsDO));
        oauthClientDetailsService.add(clientDetailsDO);
        return 1;
    }

    @RequestMapping(value = "/client/mgr/update")
    public Integer update(@Valid @RequestBody OauthClientDetailsDO clientDetailsDO) {
        logger.info("修改应用信息：{}", JSON.toJSONString(clientDetailsDO));
        oauthClientDetailsService.update(clientDetailsDO);
        return 1;
    }

    @RequestMapping(value = "/client/mgr/delete")
    public Integer delete(String clientId) {
        logger.info("删除应用信息：{}", clientId);
        return oauthClientDetailsService.delete(clientId);
    }
}
